package com.i8office.android.zhihuixinwu.module.model;

import com.cyan.tools.callback.RequestCallback;
import com.i8office.android.zhihuixinwu.app.App;
import com.i8office.android.zhihuixinwu.bean.Code;
import com.i8office.android.zhihuixinwu.bean.Empl;
import com.i8office.android.zhihuixinwu.bean.Favorite;
import com.i8office.android.zhihuixinwu.bean.Result;
import com.i8office.android.zhihuixinwu.bean.WorkSheet;
import com.i8office.android.zhihuixinwu.bean.WorkSheetNew;
import com.i8office.android.zhihuixinwu.module.contract.DetailContract;
import com.i8office.android.zhihuixinwu.util.OfficeSubscriber;


import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by pc on 2018/7/7.
 */

public class DetailModel implements DetailContract.Model {
    @Override
    public Disposable getDetail(RequestCallback<WorkSheet> callback, String mid) {
        return App.getComponent().getAPIService().getWorkSheet(mid).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Result<WorkSheet>>(callback));
    }

    @Override
    public Disposable getDetailDep(RequestCallback<WorkSheetNew> callback, String mid) {
        return App.getComponent().getAPIService().getWorkSheetDep(mid).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Result<WorkSheetNew>>(callback));
    }

    @Override
    public Disposable addFavorite(RequestCallback<Code> callback, String mid) {
        return App.getComponent().getAPIService().addFavorite(mid)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Code>(callback));
    }

    @Override
    public Disposable cancelFavorite(RequestCallback<Code> callback, String mid) {
        return App.getComponent().getAPIService().cancelFavorite(mid)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Code>(callback));
    }
    @Override
    public Disposable addDepFavorite(RequestCallback<Code> callback, String mid) {
        return App.getComponent().getAPIService().addDepFavorite(mid)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Code>(callback));
    }

    @Override
    public Disposable cancelDepFavorite(RequestCallback<Code> callback, String mid) {
        return App.getComponent().getAPIService().cancelDepFavorite(mid)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Code>(callback));
    }

    @Override
    public Disposable messageHandler(final RequestCallback<Empl> callback, Map<String, String> params) {
        return App.getComponent().getAPIService().messageHandle(params).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Result<Empl>>(callback));
    }

    @Override
    public Disposable isFavorite(RequestCallback<Favorite> callback, String mid) {
        return App.getComponent().getAPIService().isFavorite(mid).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Result<Favorite>>(callback));

    }
    @Override
    public Disposable isDepFavorite(RequestCallback<Favorite> callback, String mid) {
        return App.getComponent().getAPIService().isDepFavorite(mid).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Result<Favorite>>(callback));

    }
}
